{layout name="public/layout" /}
{include file='yxnavbar'}


<link href="/resource/components/ueditors/themes/default/css/ueditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8"  src="/resource/components/ueditors/ueditor.config.js?v=1"></script>
<script type="text/javascript" charset="utf-8" src="/resource/components/ueditors/ueditor.all.min.js?v=1"></script>
<script type="text/javascript" src="/resource/components/ueditors/lang/zh-cn/zh-cn.js"></script>
<script>
    var ueditorObj = {}
</script>

<div class="main">
    {include file='../../plugin/education/template/web/common_nav'}
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">添加礼品</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="id" value="{$item['id']}"/>
                <input type="hidden" name="themeid" value="{$themeid}"/>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>所属商家</label>
                    <div class="col-sm-8 col-xs-12">
                        <select class="form-control" name="shangjiaid">
                            <option value="0" {if empty($item['shangjiaid']) }selected="selected"{/if}>----------请选择商家----------</option>
                            {loop $shangjia  $val}
                            <option value="{$val['id']}" {if $item['shangjiaid'] == $val['id'] }selected="selected"{/if}>{$val['id']}-{$val['name']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>礼品名称</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  placeholder="请输入礼品名称" name="name"  value="{$item['name']}">
                        <span class="help-block">限20个字以内</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>礼品头图</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_image('top_img',$item['top_img']);}
                        <span class="help-block">请上传330*330(宽*高)的高清图</span>
                    </div>
                </div>
                <!--                <div class="form-group">-->
                <!--                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>礼品当前库存</label>-->
                <!--                    <div class="col-sm-8 col-xs-12">-->
                <!--                        <input type="number" class="form-control"  placeholder="请输入礼品当前库存" name="qty"  value="{$item['qty']}">-->
                <!--                    </div>-->
                <!--                </div>-->
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">礼品市场价格</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="number" class="form-control"  placeholder="请输入礼品市场价格" name="price"  value="{$item['price']}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">活动可选</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="status" value="1" {if $item['status']==1 || !$item['status']} checked="checked"{/if} type="radio"> 可选
                        </label>
                        <label class="radio-inline">
                            <input name="status" value="0" {if $item['status']===0 } checked="checked"{/if} type="radio">不可选
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>类型</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="type" value="0" {if $item['type']==0 || !$item['type']} checked="checked"{/if} type="radio">赠品
                        </label>
                        <label class="radio-inline">
                            <input name="type" value="1" {if $item['type']==1} checked="checked"{/if} type="radio"> 礼品
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>礼品内容</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_ueditor('detail', $item['detail']);}
                    </div>
                </div>
                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script type="text/javascript">
    //新增\修改奖品 提交数据
    function addOrEditItem() {
        let postUrl = "{php echo createWebUrlPlugin('education.gift.add',array('themeid'=>$themeid));}";
        let success_redirect = "{php echo createWebUrlPlugin('education.gift',array('themeid'=>$themeid));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.message)
                }else{
                    layer.msg(result.msg);
                    window.location.href = success_redirect;
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
</script>
